/* 
 * com.ctvit.framework.interceptor.TraceInteceptor.java Create on Apr 22, 2008 12:07:35 PM By Q-Wang 
 * $Header: /home/cvsroot/ctvit/messgeCenter/src/com/ctvit/framework/interceptor/TraceInteceptor.java,v 1.1 2015/12/18 01:15:49 yushihao Exp $
 */
package com.ctvit.framework.interceptor;

import java.lang.reflect.Method;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author Q-Wang
 *
 */
public class TraceInteceptor implements MethodInterceptor {
	
	private static Log log = LogFactory.getLog(TraceInteceptor.class);
	
	private boolean trace;
	
	/**
	 * @param trace the trace to set
	 */
	public void setTrace(boolean trace) {
		this.trace = trace;
	}

	/**
	 * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
	 */
	public Object invoke(MethodInvocation invocation) throws Throwable {
		if (trace) {
			Method method = invocation.getMethod();
			String clazz = method.getDeclaringClass().getName();
			log.debug("Processing:" + clazz + "." + method.toString());
			invocation.proceed(); 
			log.debug("Processing Succeed:" + clazz + "." + method.toString());
		}
		return invocation.proceed();
	}

}
